package com.coder4j.starter.generator.mapper;

import com.coder4j.starter.mybatis.BaseMapper;
import com.coder4j.starter.generator.vo.TableColumnInfo;
import com.coder4j.starter.generator.vo.ColumnInfo;
import com.coder4j.starter.generator.vo.IndexInfo;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface GeneratorMapper extends BaseMapper<TableColumnInfo> {

    /**
     * 查询表中索引，这个方法可以实现 mybatis 执行 show 语句并映射出结果集
     * 关键点：结果集类型作为查询参数类型
     *
     * @param indexInfo
     * @return
     */
    @Select("show index from ${tableName}")
    List<IndexInfo> baseQueryIndexList(IndexInfo indexInfo);

    /**
     * 查询表中字段
     *
     * @param tableName
     * @return
     */
    @Select("select column_name,is_nullable,column_type,column_comment,column_key,extra " +
            "from information_schema.COLUMNS " +
            "where TABLE_SCHEMA = (select database()) and TABLE_NAME=#{tableName} ORDER BY ordinal_position")
    List<ColumnInfo> baseQueryColumnList(String tableName);

    /**
     * 查询表注释
     * @param tableName
     * @return
     */
    @Select("SELECT table_comment FROM information_schema.TABLES WHERE table_name = #{tableName}")
    List<String> baseQueryTableComment(String tableName);



}
